package com.tdf.lolpanel.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * @param <T>
 */
@Data
public class Response<T> implements Serializable {

    private Integer code;   // 编码：1成功，0和其它数字为失败
    private String msg;     // 错误信息
    private T data;         // 数据

    public static <T> Response<T> success() {
        Response<T> response = new Response<T>();
        response.code = 1;
        return response;
    }

    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<T>();
        response.data = data;
        response.code = 1;
        return response;
    }

    public static <T> Response<T> error(String msg) {
        Response<T> response = new Response<T>();
        response.msg = msg;
        response.code = 0;
        return response;
    }
}
